$(document).ready(function ()
{
    var id = getQueryString("id");
    var dictinoaryTypeName = getQueryString("dictinoaryTypeName");

    layui.use('upload', function ()
    {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        get_model_by_id(id,dictinoaryTypeName);
    });

    $("#btn_submit").on("click", function ()
    {

        update();
    });

});

function update()
{
    var params = param();
    $.ajax({
        cache: true,
        type: "POST",
        url: ctx+"/system/dictinoary/update",
        data: params,
        async: false,
        error: function (request)
        {
            parent.layer.alert("连接错误");
        },
        success: function (data)
        {
            if (data.code == 0)
            {
                parent.layer.msg("操作成功");
                parent.get_dictinoary_List(params.dictinoaryType);
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);

            } else
            {
                parent.layer.alert(data.msg)
            }

        }
    });

}



function get_model_by_id(id,dictinoaryTypeName)
{
    $.ajax({
        type: "Get",
        url:ctx+ "/system/dictinoary/get_model_by_id",
        data: { id: id },
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        error: function (request)
        {
            parent.layer.alert("Connection error");
        },
        success: function (data)
        {
         	$("#id").val(data.id);
         	
         	
            $("#dictinoary_type").attr("dictinoaryValue", data.dictinoaryType);
            $("#dictinoary_type").val(dictinoaryTypeName);
            
            
            $("#itemvalue").val(data.itemvalue);
            $("#itemname").val(data.itemname);
            $("#order_num").val(data.orderNum);
            $("#description").val(data.description);
        }
    });
}



function param()
{
    return {
    	"id": $("#id").val(),
        "dictinoaryType": $("#dictinoary_type").attr("dictinoaryValue"),
        "itemvalue": $("#itemvalue").val(),
        "itemname": $("#itemname").val(),
        "orderNum": $("#order_num").val(),
        "description": $("#description").val()
    };
}